Fix Bug: OSError for os.stat when path not exists

Brightcells 8 years ago
parent
commit
c228f423c2
1 changed files with 9 additions and 1 deletions
  1. 9 1
      main.py

+ 9 - 1
main.py

@@ -57,6 +57,14 @@ def silent_remove(path):
57 57
             raise
58 58
 
59 59
 
60
+def silent_mode(path):
61
+    try:
62
+        flag = stat.S_IMODE(os.stat(path).st_mode) != 0555
63
+    except OSError as e:
64
+        flag = False
65
+    return flag
66
+
67
+
60 68
 def get_session_root(lensman, session):
61 69
     return '{}/{}'.format(ROOT_PATH, session)
62 70
 
@@ -205,7 +213,7 @@ class SessionEndHandler(RequestHandler):
205 213
         # Session Root
206 214
         session_root = get_session_root(lensman, session)
207 215
         # Whether Mode Has Changed
208
-        if stat.S_IMODE(os.stat(session_root).st_mode) != 0555:
216
+        if silent_mode(session_root):
209 217
             # Insert Files Into SQLite
210 218
             get_all_files(lensman, session)
211 219
             # Change Mode to 0555